\name{NormDF}
\alias{NormDF}
\title{Normalize Data Frame}
\description{Calculates "normal" data for a data frame.}
\usage{
NormDF(data, continuous = c("mean", "median", "zero"),
  discrete = c("mode", "lowest", "highest"))
}
\arguments{
  \item{data}{The data frame to have normal values calculated for.}
  \item{continuous}{How should continuous (i.e., numeric) variables be treated?  Calculates the mean, median, or 0.}
  \item{discrete}{How should discrete (e.g., logical, factor, character) variables be treated?  Options are return the mode (most frequent value), lowest or highest (by sorting).}
}
\details{This functions primary purpose is to facilitate using \code{\link{predict}}.  It creates a new data frame that matches what it was given, but with only a single row containing the "normal" value for that row, for some definition of normal.  For numeric (continuous) variables, it can calculate the mean, median, or place a 0.  For discrete variables, it finds the mode or sorts the data and then uses the lowest or highest value.  For factors, even though only a single value will be returned, it retains all the original level information.}
\value{
A data frame with 1 row and as many columns as the original.}
\author{Joshua Wiley, \url{http://joshuawiley.com/}}
\note{Hopefully I will expand the notes and details soon.}
\seealso{\code{\link{IntData}} and \code{\link{SimpleSlopes}}}
\examples{
##---- Should be DIRECTLY executable !! ----
##-- ==>  Define data, use random,
##--	or do  help(data=index)  for the standard data sets.

## The function is currently defined as
function (data, continuous = c("mean", "median", "zero"), discrete = c("mode",
    "lowest", "highest"))
{
    continuous <- match.arg(continuous)
    discrete <- match.arg(discrete)
    cFUN <- switch(continuous, mean = mean, median = median,
        zero = function(...) 0)
    dFUN <- switch(discrete, mode = function(x) {
        y <- names(sort.int(table(x, useNA = "no"), decreasing = TRUE))[1L]
        if (is.factor(x)) y <- factor(y, levels = levels(x),
            ordered = is.ordered(x))
        if (is.logical(x)) y <- as.logical(y)
        return(y)
    }, lowest = function(x) {
        if (is.factor(x)) {
            y <- factor(levels(x)[1L], levels = levels(x), ordered = is.ordered(x))
        } else y <- sort(x)[1L]
        if (is.logical(x)) y <- as.logical(y)
        return(y)
    }, highest = function(x) {
        if (is.factor(x)) {
            y <- factor(levels(x)[length(levels(x))], levels = levels(x),
                ordered = is.ordered(x))
        } else y <- sort(x)[length(x)]
        if (is.logical(x)) y <- as.logical(y)
        return(y)
    })
    as.data.frame(lapply(data, function(x) {
        if (is.numeric(x)) {
            cFUN(x, na.rm = TRUE)
        }
        else if (any(is.factor(x), is.logical(x), is.character(x))) {
            dFUN(x)
        }
        else stop("Class: '", class(x), "' is currently unsupported")
    }), stringsAsFactors = FALSE)
  }
}
\keyword{misc}
